package utile

import (
	"fmt"
)

type ExpressageData struct {
	ID                 int    `gorm:"column:id"`
	UserID             int    `gorm:"column:user_id"`
	ExpressageNumber   string `gorm:"column:expressage_number"`
	ExpressageName     string `gorm:"column:expressage_name"`
	ExpressageLocation string `gorm:"column:expressage_location"`
	AddTime            string `gorm:"column:add_time"`
	UpdateTime         string `gorm:"column:update_time"`
}

func GetExpressageData() []ExpressageData {
	var expressageDb, err = GetDB()
	if err != nil {
		fmt.Println(err)
		return nil
	}
	var expressageData []ExpressageData
	if err := expressageDb.Find(&expressageData).Error; err != nil {
		fmt.Println("Error fetching expressage data:", err)
		return nil
	}
	return expressageData
}

func UpdateExpressageLocation(trickingNumber, trickingLocation string) error {
	expressageDb, err := GetDB()
	if err != nil {
		return err
	}

	// 更新快递信息
	if err := expressageDb.Model(&ExpressageData{}).
		Where("expressage_number = ?", trickingNumber).
		Update("expressage_location", trickingLocation).Error; err != nil {
		return err
	}

	return nil
}
